import gradio as gr
from zhipuai import ZhipuAI

client = ZhipuAI(api_key="******************")

def greet(message,history):
    messages=history
    messages.append({"role": "user", "content": message})
    response = client.chat.completions.create(
    model="glm-4-plus", # 请填写您要调用的模型名称
    messages=messages,
    stream=True
)
    output=''
    for chunk in response:
        output+=chunk.choices[0].delta.content
        yield output

demo = gr.ChatInterface(
    fn=greet,
    type="messages"
)
    
demo.launch()